import request from '@/utils/request'
import { DeviceProperty } from '@/views/production_instrument/settings/deviceListSetting'
type Device = typeof DeviceProperty & { id: string }
// 获取记录列表
export function GetMeterList(data: { DBname: string }) {
  return request({
    url: 'api/MeasuringInstrument/GetMeterList',
    method: 'post',
    data
  })
}
// 添加记录
export function AddMeterRecord(data: Partial<Device>[]) {
  return request({
    url: 'api/MeasuringInstrument/MeterListAdd',
    method: 'post',
    data,
    headers: {
      'Content-Type': 'application/json'
    }
  })
}
// 修改记录
export function UpdateMeterRecord(data: Partial<Device>) {
  return request({
    url: 'api/MeasuringInstrument/MeterListUpdate',
    method: 'post',
    data
  })
}
// 删除记录
export function DeleteMeterRecord(data: { id: string }) {
  return request({
    url: `api/MeasuringInstrument/DeleteMeterList/${data.id}`,
    method: 'post'
  })
}
// 截图部分：文件相关
// 获取文件名称列表
export function GetFileListById(params: { id: string }) {
  return request({
    url: `api/MeasuringInstrument/GetMeterFileNames/${params.id}`,
    method: 'get'
  })
}
// 获取文件内容
export function GetFileData(params: { id: string; filename: string }) {
  return request({
    url: 'api/MeasuringInstrument/DownloadMeterFile',
    method: 'get',
    params,
    responseType: 'blob'
  })
}

export function UploadFileByID(data: FormData) {
  return request({
    url: 'api/MeasuringInstrument/UploadMeterFile',
    method: 'post',
    data
  })
}

export function DeleteFileByID(params: { id: string; fileName: string }) {
  return request({
    url: 'api/MeasuringInstrument/RemoveFile',
    method: 'get',
    params
  })
}
